package juntos.lbcv.utils;

// File Name SendHTMLEmail.java

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendHtmlEmail
{
   public static void run(String emailTo, String subject, String html)
   {
	   final String username = "larydev@gmail.com";
		final String password = "";

		Properties props = new Properties();
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.port", "587");

		Session session = Session.getInstance(props,
		  new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username, password);
			}
		  });


      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         message.setFrom(new InternetAddress("from-email@gmail.com"));
			
         message.setRecipients(Message.RecipientType.TO,
				InternetAddress.parse(emailTo));

         // Set Subject: header field
         message.setSubject(subject);

         // Send the actual HTML message, as big as you like
         message.setContent(html, "text/html" );

         // Send message
         Transport.send(message);
         Lbc.printOut("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}